部分引用自:http://blog.21ic.com/user1/235/archives/2009/59781.html
1. Dec 轉 Ascii
T1 = Asc("A") → 輸出: T1 為 65
T2 = Asc("B") → 輸出: T2 為 66
2. Ascii 轉 Dec
T3 = Chr(97) → 輸出: T3 為 "a"
T4 = Chr(101) → 輸出: T4 為 "e"
3. Dec 轉 Hex (十進位轉16進位)
T5 = Hex(14) → 輸出: T5 為 "E"
T6 = Hex(159) → 輸出: T6 為 "9F"
4. Hex 轉 Dex (16進位轉十進位)
參考引用:
輸入:Hex(十六進位數)
輸入數據類型:String
輸出:HEX_to_DEC(十進位數)
輸出數據類型:Long
輸入的最大數為7FFFFFFF,輸出的最大數為2147483647
→ 輸入:Hex 為 "65"
輸出: HEX_to_DEC 為 "101"
Public HEX_to_DEC(ByVal Hex As String) As Long
Dim i As Long
Dim B As Long
Hex = UCase(Hex)
For i = 1 To Len(Hex)
Select Case Mid(Hex, Len(Hex) - i + 1, 1)
Case "0": B = B + 16 ^ (i - 1) * 0
Case "1": B = B + 16 ^ (i - 1) * 1
Case "2": B = B + 16 ^ (i - 1) * 2
Case "3": B = B + 16 ^ (i - 1) * 3
Case "4": B = B + 16 ^ (i - 1) * 4
Case "5": B = B + 16 ^ (i - 1) * 5
Case "6": B = B + 16 ^ (i - 1) * 6
Case "7": B = B + 16 ^ (i - 1) * 7
Case "8": B = B + 16 ^ (i - 1) * 8
Case "9": B = B + 16 ^ (i - 1) * 9
Case "A": B = B + 16 ^ (i - 1) * 10
Case "B": B = B + 16 ^ (i - 1) * 11
Case "C": B = B + 16 ^ (i - 1) * 12
Case "D": B = B + 16 ^ (i - 1) * 13
Case "E": B = B + 16 ^ (i - 1) * 14
Case "F": B = B + 16 ^ (i - 1) * 15
End Select
Next i
HEX_to_DEC = B
End
============================================================
自己的需求: asp將一串hex轉ascii
範例: 將 736D696C65 轉成 smile
pwo="736D696C65"
pw=""
j=1
For ti=1 to 9
d = Mid(pwo, j, 2)
Dim i
Dim B
hex16 = UCase(d)
For i = 1 To Len(hex16)
Select Case Mid(hex16, Len(hex16) - i + 1, 1)
Case "0": B = B + 16 ^ (i - 1) * 0
Case "1": B = B + 16 ^ (i - 1) * 1
Case "2": B = B + 16 ^ (i - 1) * 2
Case "3": B = B + 16 ^ (i - 1) * 3
Case "4": B = B + 16 ^ (i - 1) * 4
Case "5": B = B + 16 ^ (i - 1) * 5
Case "6": B = B + 16 ^ (i - 1) * 6
Case "7": B = B + 16 ^ (i - 1) * 7
Case "8": B = B + 16 ^ (i - 1) * 8
Case "9": B = B + 16 ^ (i - 1) * 9
Case "A": B = B + 16 ^ (i - 1) * 10
Case "B": B = B + 16 ^ (i - 1) * 11
Case "C": B = B + 16 ^ (i - 1) * 12
Case "D": B = B + 16 ^ (i - 1) * 13
Case "E": B = B + 16 ^ (i - 1) * 14
Case "F": B = B + 16 ^ (i - 1) * 15
End Select
Next
pw=pw+Chr(B)
j=j+2
B=0
next
response.write pw
=========================================================
相關錯誤:
1. 800a0401 _ 必須是陳述式的結尾
當像引用範例一樣使用:
Dim i As Long
Dim B As Long
就會出現這項錯誤
因為ASP的陣列跟變數一樣都是可變型態的,所以不需要事先定義型態
所以只要寫
Dim i
Dim B
即可
no msg a little sad ,
i'm moving when you oil the MENTHOLATUM on my leg